package com.ruowei.modules.sys.web;

import com.ruowei.modules.sys.utils.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/redis")
@Api(tags = "redis使用示例")
public class RedisExampleResource {
    private final RedisUtil redisUtil;

    public RedisExampleResource(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
    }

    @PostMapping("/set")
    @ApiOperation(value = "redis插入数值")
    public boolean set(String key, String value) {
        return redisUtil.set(key, value);
    }

    @PostMapping("/setWithTime")
    @ApiOperation(value = "redis插入数值,同时设置有效时间，单位秒")
    public boolean setWithTime(String key, String value, Long time) {
        return redisUtil.set(key, value, time);
    }

    @GetMapping("/get")
    @ApiOperation(value = "redis根据键值获取数值")
    public Object get(String key) {
        return redisUtil.get(key);
    }
}
